
<script src="../js/jquery-2.1.0.min.js" type="text/javascript"></script>
<script src="../js/jquery-ui.js"></script>
<script src="../js/popup.js" type="text/javascript"></script>
<script src="../js/checker.js" type="text/javascript"></script>

<script>
	$('#title').append("<h1>" + "Quiz Summary" + "</h1>");
	$('#summary').hide();
	
	var course		= localStorage.getItem("estudia_course");
	var chapter		= (localStorage.getItem("estudia_chapter")).charAt(0);
	var code		= course.substr(0,3) + "_" + "quiz" + chapter;
	
	var jawaban_benar 	= localStorage.getItem("estudia_ans_right");
	var jawaban_salah 	= localStorage.getItem("estudia_ans_false");
	var tambahan_point	= (parseInt(jawaban_benar) * 20) + (parseInt(jawaban_salah) * 5);

	if (jawaban_benar == 5) {
		tambahan_point += 10;
	}
	
	if (localStorage.getItem("estudia_additionalpoint") == null) {
	
	} else {
		tambahan_point += parseInt(localStorage.getItem("estudia_additionalpoint"));
	}
	
	var current_level	= localStorage.getItem("estudia_level");
	var current_exp		= localStorage.getItem("estudia_exp");
	
	var next_level		= parseInt(current_level);
	var next_exp 		= parseInt(current_exp) + tambahan_point;
	
	var username		= localStorage.getItem("estudia_user");
	
	if ( next_exp >= 100) {
		next_level 	+= 1;
		next_exp	-= 100;
		
		if (next_level == 2) {
			createPopUp("b07", "notificator");
		} else {
			createPopUp("lvl" + next_level, "notificator");
		}
		
		if ( next_exp >= 100) {
			next_level 	+= 1;
			next_exp	-= 100;
		}
		
		localStorage.setItem("estudia_level", next_level);
		localStorage.setItem("estudia_exp", next_exp);

	} else {
		localStorage.setItem("estudia_exp", next_exp);

	}
	
	if (localStorage.getItem("estudia_achievment_b03") == "0") {
		createPopUp("b03", "notificator");
	}	
	
	if ((jawaban_benar == 5) && (localStorage.getItem("estudia_achievment_b04") == "0")) {
		createPopUp("b04", "notificator");
	}
	
	if (localStorage.getItem("estudia_" + code) == 0) {
		//alert("sebelumnya belum pernah");
		localStorage.setItem("estudia_" + code, (parseInt(jawaban_benar) * 20));
		
		if (localStorage.getItem("estudia_achievment_b06") == "0") {
			checkAQuiz(course.substr(0,3), function(data) {
				if (data == true) {
					createPopUp("b06", "notificator");
				}
			});
		}

		
		if (localStorage.getItem("estudia_achievment_b09") == "0") {
			checkAllQuiz(function(data) {
				if (data == true) {
					createPopUp("b09", "notificator");
				}
			});
		}
		
		$.get("http://estudiahapid.ap01.aws.af.cm/services/changeprogress.php?username=" + username + "&query=" + code + "&value=" + (parseInt(jawaban_benar) * 20), function(data) {
			var result = JSON.parse(data);
			
			if (result["status"] == "success") {
				//alert("success");
			} else {
				//alert("failed");
			}
		}).done(function (data) {

		}); // */
	} else if (localStorage.getItem("estudia_" + code) < (parseInt(jawaban_benar) * 20)) {
		localStorage.setItem("estudia_" + code, (parseInt(jawaban_benar) * 20));
		
		$.get("http://estudiahapid.ap01.aws.af.cm/services/changeprogress.php?username=" + username + "&query=" + code + "&value=" + (parseInt(jawaban_benar) * 20), function(data) {
			var result = JSON.parse(data);
			
			if (result["status"] == "success") {
				//alert("success");
			} else {
				//alert("failed");
			}
		}).done(function (data) {

		}); // */
		
		if (((parseInt(jawaban_benar) * 20) >= 80) && (localStorage.getItem("estudia_achievment_b10") == "0")) {
			checkCumLaude(function(data) {
				if (data == true) {
					createPopUp("b10", "notificator");
				}
			});		
		}
		
	}
	
	
	$.get("http://estudiahapid.ap01.aws.af.cm/services/addpoint.php?username=" + username + "&lvl=" + next_level + "&exp=" + next_exp + "", function(data) {
		var result = JSON.parse(data);
		
		if (result["status"] == "success") {
			//alert("success");
		} else {
			//alert("failed");
		}
	}).done(function (data) {

	}); //*/
	
	$('#right_answer').append("<h3>= " + jawaban_benar + "</h3>");
	$('#wrong_answer').append("<h3>= " + jawaban_salah + "</h3>");
	$('#score').append("<h3>= " + (parseInt(jawaban_benar) * 2) + "/10</h3>");
	$('#point_addition').append("<h3>= " + tambahan_point + "</h3>");
	
	
	$( "#new_progressbar" ).progressbar({
      value: parseInt(next_exp)
    });// */
	
	$('#new_progressbar_detail').append("<h6>" + next_exp + " / " + "100" + "</h6>");

	if (current_level < next_level) {
		$('#new_level').append("<h2> Level " + next_level + " Up! </h2>");
	} else {
		$('#new_level').append("<h2> Level " + next_level + "</h2>");
	}
	
	$('#user_rank_level').empty();
	$('#user_rank_progressbar_detail').empty();
	$( "#user_rank_progressbar" ).empty();
	
	$('#user_rank_level').append("<h1>Level " + localStorage.getItem("estudia_level") + "</h1>");
	$('#user_rank_progressbar_detail').append("<h6>" + localStorage.getItem("estudia_exp") + " / " + "100" + "</h6>");
	$( "#user_rank_progressbar" ).progressbar({
      value: parseInt(next_exp)
    });
	
	$('#summary').show();
	
function capitalise(string) {
	return string.charAt(0).toUpperCase() + string.slice(1);
};	
</script>

<div id="title"></div>
<div id="summary">
	<div id="summary_detail">
		<div id="left_side">
			<span><h3>Jawaban Benar</h3></span>
			<span><h3>Jawaban Salah</h3></span>
			<span><h3>Skor</h3></span>
			<span><h3>Tambahan Point</h3></span>
		</div>
			
		<div id="right_side">
			<span id="right_answer"></span>
			<span id="wrong_answer"></span>
			<span id="score"></span>
			<span id="point_addition"></span>
		</div>
	</div>
	
	<div id="new_point">
		<span id="new_level"></span>
		<div id="new_progressbar"></div>
		<span id="new_progressbar_detail"></span>
	</div>
</div>
